//本地测试地址
//export const IP = "http://192.168.1.11:10014/dev-api/"
export const IP = "https://www.sdsjms.com/prod-api/"
//export const ImgIP = "http://182.40.192.2:10002/prod-api"
export const ImgIP = "https://www.sdsjms.com/prod-api"
//之前有大部分地方都用了ImgBase  这里就先不删
export const tokenKey = "tokenKey"
/**
 函数节流
 fn 函数
 wait 延迟执行毫秒数
 type 1 使用表时间戳，在时间段开始的时候触发 2 使用表定时器，在时间段结束的时候触发
 */
export const throttle = function(fn, wait = 1000, type = 1) {
	let previous = 0;
	let timeout;
	return function() {
		let that = this;
		let args = arguments;
		if (type === 1) {
			let now = Date.now();
			if (now - previous > wait) {
				fn.apply(that, args);
				previous = now;
			}
		} else if (type === 2) {
			if (!timeout) {
				timeout = setTimeout(() => {
					timeout = null;
					fn.apply(that, args)
				}, wait)
			} else {
				console.log('休息一会吧别点了')
			}
		}
	}
}

/**
  函数防抖
  fn 目标函数
  wait 延迟执行毫秒数
  immediately true - 立即执行， false - 延迟执行
 */
export const debounce = function(fn, wait = 1000, immediately = true) {
	let timer;
	return function() {
		let that = this,
			args = arguments;
		if (timer) clearTimeout(timer);
		if (immediately) {
			let callNow = !timer;
			timer = setTimeout(() => {
				timer = null;
			}, wait);
			if (callNow) fn.apply(that, args);
		} else {
			timer = setTimeout(() => {
				fn.apply(that, args);
			}, wait)
		}
	}
}